package kiwi.assist.dev.guieditor.view {
	import kiwi.assist.dev.guieditor.GuiEditorConstants;

	import org.aswing.Container;
	import org.aswing.JButton;
	import org.aswing.JLabel;
	import org.aswing.JPanel;
	import org.aswing.JSlider;
	import org.aswing.event.InteractiveEvent;
	import org.aswing.plaf.basic.icon.FrameNormalIcon;

	import flash.events.Event;
	import flash.events.MouseEvent;

	/**
	 * @author zhangming.luo
	 */
	public class ScrollControllerPanel extends JPanel {
		private var scaleSlider : JSlider;
		private var target : Container;

		public function ScrollControllerPanel(target : Container) {
			this.target = target;
			scaleSlider = new JSlider();
			scaleSlider.setPreferredWidth(200);
			scaleSlider.setMaximum(GuiEditorConstants.PREVIEW_SCALE.length);
			scaleSlider.setMinimum(1);
			scaleSlider.addEventListener(InteractiveEvent.STATE_CHANGED, function() : void {
				var value : int = scaleSlider.getValue();
				scaleLabel.setText((GuiEditorConstants.PREVIEW_SCALE[value - 1] * 100) + "%");
				target.scaleX = target.scaleY = GuiEditorConstants.PREVIEW_SCALE[value - 1];
			});
			var scaleLabel : JLabel = new JLabel;
			scaleLabel.setPreferredWidth(40);
			var resetButton : JButton = new JButton();
			resetButton.setIcon(new FrameNormalIcon);
			resetButton.setToolTipText("100%显示");
			resetButton.addEventListener(MouseEvent.CLICK, function(e : Event) : void {
				scaleSlider.setValue(GuiEditorConstants.PREVIEW_SCALE.indexOf(1) + 1);
			});
			scaleSlider.setValue(GuiEditorConstants.PREVIEW_SCALE.indexOf(1) + 1);
			appendAll(scaleSlider, scaleLabel, resetButton);
		}
	}
}
